package com.senthink.gl.business.domain.repository;

import com.senthink.gl.business.forgetpw.ForgetPassword;
import com.senthink.gl.business.common.exception.DataAccessException;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.transaction.annotation.Transactional;

import java.util.Optional;

/**
 * 重置密码持久化接口
 * @author yuanpeng@senthink.com
 * @data 2018-01-24 15:34
 */

public interface ForgetPasswordRepository extends JpaRepository<ForgetPassword, Long> {

    /**
     * 获取重置密码对象容器
     * @param account 账户
     * @return
     */
    Optional<ForgetPassword> findTopByAccount(String account);

    /**
     * 对重置密码实体进行计数
     * @param account
     * @param code
     * @param reset
     * @return
     */
    long countByAccountAndCodeAndReset(String account, String code, boolean reset);

    /**
     * 删除重置密码校验码
     * @param account
     */
    @Transactional(rollbackFor = DataAccessException.class)
    void deleteByAccount(String account);
}
